var boolCheck = true;
function checkOrgPsw() {
	var orgPsw = toTrim(getValue("orgPsw"));
	var userId = getValue("strUserId");
		
	if (orgPsw == "") {
		boolCheck = false;
		jQuery("#Spn1").text("原密码不能为空");
	} else {
		boolCheck = true;
		jQuery("#Spn1").text("");
		checkOrgPswCommon(orgPsw, userId);

	}
}

function checkOrgPswCommon(orgPsw, userId) {
    ajaxRequest(getHost() + "user/changePsw/checkorgpsw", {
        "orgPsw"  : orgPsw,
        "UserId"  : userId
    }, checkOrgPsw_callback);
}

function checkOrgPsw_callback(data) {
	if (data == true) {
		jQuery("#Spn1").text("");
	} else {
		boolCheck = false;
		jQuery("#Spn1").text("原密码不正确");
	}
}

function checkNewPsw(){
	var newPsw = toTrim(getValue("newPsw"));
	if (newPsw == "") {
		boolCheck = false;
		jQuery("#Spn2").text("新密码不能为空");
	} else {
		boolCheck = true;
		jQuery("#Spn2").text("");
	}
}
function checkTwicePsw() {
	var newPsw = toTrim(getValue("newPsw"));
	var againPsw = toTrim(getValue("againPsw"));
	if (newPsw != againPsw) {
		boolCheck = false;
		jQuery("#Spn3").text("两次密码不一致");
	} else {
		boolCheck = true;
		jQuery("#Spn3").text("");
	}
}

function changePsw() {
	var userId   = getValue("strUserId");
	var orgPsw   = toTrim(getValue("orgPsw"));
	var newPsw   = toTrim(getValue("newPsw"));
	var againPsw = toTrim(getValue("againPsw"));
	
	if (orgPsw == "" || newPsw == "" || againPsw == "") {
		jQuery("#Spn4").text("密码不能为空");
	} else {
		if (orgPsw == newPsw){
			jQuery("#Spn4").text("密码没有更改");
			return;
		}

		jQuery("#Spn4").text("");
		if (boolCheck == false) {
			return;
		} else {
			checkOrgPswCommon(orgPsw, userId);
			if (boolCheck == false) {
				return;
			} else {
			    ajaxRequest(getHost() + "user/changePsw/updatepsw", {
			        "orgPsw"  : orgPsw,
			        "newPsw"  : newPsw,
			        "userId"  : userId
			    }, changePsw_callback);
			}
		}
	}
}

function changePsw_callback(data) {
	if (data == true) {
		document.getElementById("changePswForm").action = getHost() + "user/changePsw/changecomplete";
	    document.getElementById("changePswForm").submit();
	} else {
		return;
	}
}